package utils
{
	import flash.display.DisplayObject;
	import flash.filters.BlurFilter;
	import flash.filters.ColorMatrixFilter;
	import flash.filters.DropShadowFilter;
	import flash.filters.GlowFilter;
	import flash.geom.ColorTransform;
	
    public class ColorUtil
    {
        public static const RGB_ORANGE:uint = 16751104;
        public static var timer:EnterFrameTimer;
        public static const RGB_LIGHTGRAY:uint = 13421772;
        public static const RGB_BLACK:uint = 0;
        public static const RGB_PURPLE:uint = 13070590;
        public static const RGB_GREEN:uint = 2678100;
        private static var fadeFilter:ColorMatrixFilter = new ColorMatrixFilter([1 / 3, 1 / 3, 1 / 3, 0, 0, 1 / 3, 1 / 3, 1 / 3, 0, 0, 1 / 3, 1 / 3, 1 / 3, 0, 0, 0, 0, 0, 1, 0]);
        public static const RGB_RED:uint = 16711680;
        public static const RGB_BLUE:uint = 6790655;
        public static const RGB_GOLD:uint = 16304960;
        public static var blackColorTrans:ColorTransform = new ColorTransform(0.4, 0.4, 0.4, 1, 0.5, 0.5, 0.5);
        public static const RGB_GRAY:uint = 11184810;
        public static const RGB_WHITE:uint = 16777215;
        private static var highLightTransform:ColorTransform = new ColorTransform(1, 1, 1, 1, 50, 50, 0, 0);
        public static const RGB_SLATE_BLUE:uint = 6970061;
        public static var defaultTransform:ColorTransform = new ColorTransform(1, 1, 1, 1, 0, 0, 0, 0);

        public function ColorUtil()
        {
            return;
        }// end function

        public static function deFadeColor(param1:DisplayObject) : void
        {
            var _loc_4:ColorMatrixFilter = null;
            var _loc_5:Boolean = false;
            var _loc_6:Array = null;
            var _loc_7:Array = null;
            var _loc_8:int = 0;
            var _loc_2:* = param1.filters;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2.length)
            {
                
                _loc_4 = _loc_2[_loc_3] as ColorMatrixFilter;
                if (_loc_4 == null)
                {
                }
                else
                {
                    _loc_5 = true;
                    _loc_6 = _loc_4.matrix;
                    _loc_7 = fadeFilter.matrix;
                    _loc_8 = 0;
                    while (_loc_8 < 20)
                    {
                        
                        if (_loc_6[_loc_8] != _loc_7[_loc_8])
                        {
                            _loc_5 = false;
                            break;
                        }
                        _loc_8++;
                    }
                    if (_loc_5)
                    {
                        _loc_2.splice(_loc_3, 1);
                        break;
                    }
                }
                _loc_3++;
            }
            param1.filters = _loc_2;
            param1.transform.colorTransform = defaultTransform;
            return;
        }// end function

        public static function addColorRing(param1:DisplayObject, param2:uint = 13421568, param3:Number = 3, param4:Number = 6) : void
        {
            var _loc_5:Array = null;
            var _loc_6:GlowFilter = null;
            var _loc_7:String = null;
            if (param1)
            {
                _loc_5 = param1.filters;
                for (_loc_7 in _loc_5)
                {
                    
                    if (_loc_5[_loc_7] is GlowFilter)
                    {
                        _loc_6 = _loc_5[_loc_7];
                        break;
                    }
                }
                if (_loc_6)
                {
                    _loc_6.color = param2;
                }
                else
                {
                    _loc_6 = new GlowFilter(param2, 1, param3, param3, param4, 2);
                    _loc_5.push(_loc_6);
                }
                param1.filters = _loc_5;
            }
            return;
        }// end function

        public static function deHighLight(param1:DisplayObject) : void
        {
            param1.transform.colorTransform = defaultTransform;
            return;
        }// end function

        public static function highLight(param1:DisplayObject) : void
        {
            param1.transform.colorTransform = highLightTransform;
            return;
        }// end function

        public static function removeColorRing(param1:DisplayObject) : void
        {
            var _loc_2:int = 0;
            var _loc_3:Array = null;
            if (param1 && param1.filters)
            {
                _loc_2 = 0;
                while (_loc_2 < param1.filters.length)
                {
                    
                    if (param1.filters[_loc_2] is GlowFilter)
                    {
                        _loc_3 = param1.filters;
                        _loc_3.splice(_loc_2, 1);
                        param1.filters = _loc_3;
                    }
                    _loc_2++;
                }
            }
            return;
        }// end function

        public static function addShadow(param1:DisplayObject, param2:int = 4, param3:int = 1, param4:Number = 0.5) : void
        {
            var _loc_5:* = new DropShadowFilter(param2, 45, 0, param4, 2, 2, param3);
            var _loc_6:* = param1.filters;
            param1.filters.push(_loc_5);
            param1.filters = _loc_6;
            return;
        }// end function

        public static function addBlur(param1:DisplayObject, param2:int) : void
        {
            var _loc_3:BlurFilter = null;
            var _loc_4:Array = null;
            var _loc_5:String = null;
            if (param1)
            {
                _loc_4 = param1.filters;
                for (_loc_5 in _loc_4)
                {
                    
                    if (_loc_4[_loc_5] is BlurFilter)
                    {
                        _loc_3 = _loc_4[_loc_5];
                        break;
                    }
                }
                if (_loc_3)
                {
                    var _loc_6:* = param2;
                    _loc_3.blurY = param2;
                    _loc_3.blurX = _loc_6;
                }
                else
                {
                    _loc_3 = new BlurFilter(param2, param2);
                    _loc_4.push(_loc_3);
                }
                param1.filters = _loc_4;
            }
            return;
        }// end function

        public static function fadeColor(param1:DisplayObject) : void
        {
            deFadeColor(param1);
            var _loc_2:* = param1.filters;
            _loc_2.push(fadeFilter);
            param1.filters = _loc_2;
            param1.transform.colorTransform = new ColorTransform(0.8, 0.8, 0.8, 1, 10, 10, 10, 0);
            return;
        }

        public static function setTint(param1:uint = 16777215, param2:Number = 0) : ColorTransform
        {
            var _loc_3:* = new ColorTransform();
            var _loc_7:* = 1 - param2;
            _loc_3.blueMultiplier = 1 - param2;
            _loc_3.greenMultiplier = _loc_7;
            _loc_3.redMultiplier = _loc_7;
            var _loc_4:* = param1 >> 16 & 255;
            var _loc_5:* = param1 >> 8 & 255;
            var _loc_6:* = param1 & 255;
            _loc_3.redOffset = Math.round(_loc_4 * param2);
            _loc_3.greenOffset = Math.round(_loc_5 * param2);
            _loc_3.blueOffset = Math.round(_loc_6 * param2);
            return _loc_3;
        }
    }
}